home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / unix / volume23 / sc6.8 / part05 < prev    next >
Encoding:
Internet Message Format  |  1990-10-09  |  54.0 KB

  1. Subject:  v23i025:  The SC Spreadsheet, release 6.8, Part05/06
  2. Newsgroups: comp.sources.unix
  3. Approved: rsalz@uunet.UU.NET
  4. X-Checksum-Snefru: 191a9280 14982b2b efb671e4 f64ffc17
  5.  
  6. Submitted-by: Jeff Buhrt <sawmill!buhrt>
  7. Posting-number: Volume 23, Issue 25
  8. Archive-name: sc6.8/part05
  9.  
  10. #! /bin/sh
  11. # This is a shell archive.  Remove anything before this line, then feed it
  12. # into a shell via "sh file" or similar.  To overwrite existing files,
  13. # type "sh file -c".
  14. # The tool that generated this appeared in the comp.sources.unix newsgroup;
  15. # send mail to comp-sources-unix@uunet.uu.net if you want that tool.
  16. # Contents:  CHANGES eres.sed gram.y psc.doc range.c sc.h version.c
  17. #   vi.c vmtbl.c
  18. # Wrapped by rsalz@litchi.bbn.com on Fri Jul 13 15:24:22 1990
  19. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  20. echo If this archive is complete, you will see the following message:
  21. echo '          "shar: End of archive 5 (of 6)."'
  22. if test -f 'CHANGES' -a "${1}" != "-c" ; then 
  23.   echo shar: Will not clobber existing file \"'CHANGES'\"
  24. else
  25.   echo shar: Extracting \"'CHANGES'\" \(5088 characters\)
  26.   sed "s/^X//" >'CHANGES' <<'END_OF_FILE'
  27. XCHANGES BETWEEN 6.1 and 6.7
  28. X
  29. XDave Lewis - 
  30. X    Found and fixed a null pointer derefrece in the 'R' command.
  31. X
  32. XRob McMahon -
  33. X    Changed the ctl() macro to work with ANSI style compilers.
  34. X    Cleaned up some non-readonly text problems.
  35. X
  36. XRick Linck -
  37. X    Fixed a bug in lex.c - Ann Arbor Ambassadors have long ks and ke
  38. X    termcap entries.
  39. X
  40. XSam Drake -
  41. X    A fix for undefined C_* symbols in AIX.
  42. X
  43. XPeter Brower -
  44. X    Cleaned up the INTERNATIONAL ifdefs with more portable code.
  45. X
  46. XGlen Ditchfield
  47. X    Cleaned up a problem in crypt.c when the encrypted file shrank.
  48. X
  49. XBob Bond -
  50. X    Vi style editing for the command line.
  51. X    A bug in range name aliases.
  52. X
  53. XJeff Buhrt -
  54. X    -Added "~" filename expansion.
  55. X    -702 columns (A-ZZ) and unlimited rows/cells based on max. memory
  56. X    -fixed a few bugs
  57. X    -slightly decreased CPU usage
  58. X    -MAKES backup copies of files
  59. X    -understands ~$HOME stuff
  60. X
  61. XCHANGES BETWEEN 5.1 and 6.1:
  62. X
  63. XAndy Valencia -
  64. X    xmalloc aligns data to a double boundary.
  65. X
  66. XLawrence Cipriani -
  67. X    Fixed a bug in the "do you want to save this" sequence.
  68. X
  69. XSoren Lundsgaard -
  70. X    A null pointer derefrence.
  71. X
  72. XRick Perry -
  73. X    Cleaned up a problem with modchk() in sc.c.
  74. X
  75. XGregory Bond -
  76. X    Added code for multi argument versions of @min and @max.
  77. X
  78. XTad Mannes -
  79. X    Added code to save/restore hidden rows and columns when the
  80. X    data base is saved or restored.
  81. X
  82. XMarius Olafsson -
  83. X    INTERNATIONAL changes.  Allows full 8 bit characters (if
  84. X    curses supports them.)
  85. X
  86. XKurt Horton -
  87. X    Added support for @pv, @fv and @pmt financial functins.
  88. X    Tested lots of different systems, linting.
  89. X
  90. XJohn Campbell -
  91. X    Support for VMS.  See VMS_NOTES.
  92. X
  93. XPeter King -
  94. X     User selection of row or column order for recalculation.
  95. X        Also affects order of traversing regions in /f and /r
  96. X     User setting of automatic or manual recalculation.
  97. X     User setting of number of times to try recalculation.
  98. X     + and - commands when in non-numeric mode to do 
  99. X        increment and decrement operations.
  100. X    @index, @stindex, @atan2, @lookup  functions.
  101. X    Save/restore options.
  102. X    Support for TeX, LaTeX, and better support for tbl in "T" cmd.
  103. X    Provision of a copyent function to copy entries (same code repeated
  104. X        in several locations)
  105. X    Forwrow, backrow, forwcol, backcol functions to replace
  106. X        repeated code
  107. X    Correct interpretation of ESCAPE or ^G as an abort when in a 
  108. X        two character command such as 'ar' or 'ac'
  109. X    Cleanup in eval() - catches non-trap function errors.
  110. X
  111. XBob Bond - 
  112. X       Added search options to "g".
  113. X       Added supression of hidden columns to "W"
  114. X       Added the mod operator "%"
  115. X       New help functions.
  116. X       Constant prescale "$"
  117. X       Added string matching to @lookup.
  118. X       Some more bug fixes.
  119. X       Testing, integration, documentation.
  120. X
  121. XAlan Silverstein-
  122. X    Greatly revised the manual entry.
  123. X    Added menus for ^E command and row/column commands, which
  124. X    involved a bunch of code cleanup.
  125. X
  126. X    Changed top row display to clearly indicate string labels
  127. X    versus number parts, and to distinguish string functions from
  128. X    constant labels.
  129. X
  130. X    When the character cursor is on a cell (not topline), ^H
  131. X    (backspace) is like ^B (move back one cell), rather than being
  132. X    ignored.
  133. X
  134. X    When the character cursor is on a cell (not topline), ^I (tab)
  135. X    is like ^F (move forward one cell), rather than being ignored.
  136. X    ^R is no longer identical with ^L.  Now ^R highlights all cells
  137. X    which should be entered by a user because they contain constant
  138. X    numeric values (not the result of a numeric expression).
  139. X
  140. X    Added a ^X command, similar to ^R, which highlights cells which
  141. X    have expressions.  It also displays the expressions in the
  142. X    highlighted cells as left-justified strings, instead of the
  143. X    label and/or value of the cell.
  144. X
  145. X    Added indirection functions (@nval() and @sval()) for simple
  146. X    table lookups.  Given a column name and row number, they return
  147. X    the numeric or string value of the selected cell.
  148. X
  149. X    Added external functions (@ext()) for non-trivial
  150. X    computations.  Given a command name and argument, it calls the
  151. X    command and reads back one output line.
  152. X
  153. X    Added a ^T,e command to toggle enabling of external functions.
  154. X
  155. X    Changed ^T,t to only control the top line display, and added
  156. X    ^T,c to control current cell highlighting.  (Separated the
  157. X    functions.)
  158. X
  159. X    "!" (shell escape) gives a vi-style warning if there were any
  160. X    changes since the last write.  (No change to manual entry.)
  161. X
  162. X    Fixed some startup, error, and prompt messages to be cleaner
  163. X    and/or more consistent.  (No changes to manual entry.)
  164. X
  165. X    Fixed a bug:  If @substr() upper bound (third parameter) is
  166. X    past the end of the string operand, return the substring
  167. X    through the end of the string, rather than returning a null
  168. X    string.
  169. X
  170. X    Fixed a bug:  Reset SIGINT to default after forking before
  171. X    calling shell escape program and before starting pipeline (for
  172. X    commands which support this).  Didn't reset SIGINT before
  173. X    calling crypt and external functions because in both cases it
  174. X    should be irrelevant.  (No change to manual entry.)
  175. X
  176. XCHANGES BETWEEN 6.1 and 6.2:
  177. X
  178. X
  179. XChris Cole-
  180. X    Compatibility with Lotus 1-2-3
  181. X        a) @hlookup(expr,range,expr)
  182. X        b) @vlookup(expr,range,expr)
  183. X        c) @round(expr,expr)
  184. X        d) @if(expr,expr,expr)
  185. X        e) @abs(expr)
  186. END_OF_FILE
  187.   if test 5088 -ne `wc -c <'CHANGES'`; then
  188.     echo shar: \"'CHANGES'\" unpacked with wrong size!
  189.   fi
  190.   # end of 'CHANGES'
  191. fi
  192. if test -f 'eres.sed' -a "${1}" != "-c" ; then 
  193.   echo shar: Will not clobber existing file \"'eres.sed'\"
  194. else
  195.   echo shar: Extracting \"'eres.sed'\" \(50 characters\)
  196.   sed "s/^X//" >'eres.sed' <<'END_OF_FILE'
  197. X/%token.*K_/!d
  198. X/%token.*K_\(.*\)/s//    "\1",    K_\1,/
  199. END_OF_FILE
  200.   if test 50 -ne `wc -c <'eres.sed'`; then
  201.     echo shar: \"'eres.sed'\" unpacked with wrong size!
  202.   fi
  203.   # end of 'eres.sed'
  204. fi
  205. if test -f 'gram.y' -a "${1}" != "-c" ; then 
  206.   echo shar: Will not clobber existing file \"'gram.y'\"
  207. else
  208.   echo shar: Extracting \"'gram.y'\" \(12082 characters\)
  209.   sed "s/^X//" >'gram.y' <<'END_OF_FILE'
  210. X/*    SC    A Spreadsheet Calculator
  211. X *        Command and expression parser
  212. X *
  213. X *        original by James Gosling, September 1982
  214. X *        modified by Mark Weiser and Bruce Israel,
  215. X *            University of Maryland
  216. X *
  217. X *         more mods Robert Bond 12/86
  218. X *
  219. X *        More mods by Alan Silverstein, 3/88, see list of changes.
  220. X *
  221. X *        $Revision: 6.8 $
  222. X */
  223. X
  224. X
  225. X
  226. X%{
  227. X#include <curses.h>
  228. X#include "sc.h"
  229. X
  230. X#define ENULL (struct enode *)0
  231. X
  232. Xchar *strcpy();
  233. X%}
  234. X
  235. X%union {
  236. X    int ival;
  237. X    double fval;
  238. X    struct ent_ptr ent;
  239. X    struct enode *enode;
  240. X    char *sval;
  241. X    struct range_s rval;
  242. X}
  243. X
  244. X%type <ent> var
  245. X%type <fval> num
  246. X%type <rval> range
  247. X%type <rval> var_or_range
  248. X%type <sval> strarg
  249. X%type <enode> e term expr_list
  250. X%token <sval> STRING
  251. X%token <ival> NUMBER
  252. X%token <fval> FNUMBER
  253. X%token <rval> RANGE
  254. X%token <rval> VAR
  255. X%token <sval> WORD
  256. X%token <ival> COL
  257. X%token S_FORMAT
  258. X%token S_LABEL
  259. X%token S_LEFTSTRING
  260. X%token S_RIGHTSTRING
  261. X%token S_GET
  262. X%token S_PUT
  263. X%token S_MERGE
  264. X%token S_LET
  265. X%token S_WRITE
  266. X%token S_TBL
  267. X%token S_COPY
  268. X%token S_SHOW
  269. X%token S_ERASE
  270. X%token S_FILL
  271. X%token S_GOTO
  272. X%token S_DEFINE
  273. X%token S_UNDEFINE
  274. X%token S_VALUE
  275. X%token S_MDIR
  276. X%token S_HIDE
  277. X%token S_SET
  278. X
  279. X%token K_FIXED
  280. X%token K_SUM
  281. X%token K_PROD
  282. X%token K_AVG
  283. X%token K_STDDEV
  284. X%token K_COUNT
  285. X%token K_ABS
  286. X%token K_ACOS
  287. X%token K_ASIN
  288. X%token K_ATAN
  289. X%token K_ATAN2
  290. X%token K_CEIL
  291. X%token K_COS
  292. X%token K_EXP
  293. X%token K_FABS
  294. X%token K_FLOOR
  295. X%token K_HYPOT
  296. X%token K_LN
  297. X%token K_LOG
  298. X%token K_PI
  299. X%token K_POW
  300. X%token K_SIN
  301. X%token K_SQRT
  302. X%token K_TAN
  303. X%token K_DTR
  304. X%token K_RTD
  305. X%token K_MAX
  306. X%token K_MIN
  307. X%token K_RND
  308. X%token K_ROUND
  309. X%token K_IF
  310. X
  311. X%token K_PV
  312. X%token K_FV
  313. X%token K_PMT
  314. X
  315. X%token K_HOUR
  316. X%token K_MINUTE
  317. X%token K_SECOND
  318. X%token K_MONTH
  319. X%token K_DAY
  320. X%token K_YEAR
  321. X%token K_NOW
  322. X%token K_DATE
  323. X%token K_DTS
  324. X%token K_TTS
  325. X%token K_FMT
  326. X%token K_SUBSTR
  327. X%token K_STON
  328. X%token K_EQS
  329. X%token K_EXT
  330. X%token K_NVAL
  331. X%token K_SVAL
  332. X%token K_LOOKUP
  333. X%token K_HLOOKUP
  334. X%token K_VLOOKUP
  335. X%token K_INDEX
  336. X%token K_STINDEX
  337. X%token K_AUTO
  338. X%token K_AUTOCALC
  339. X%token K_BYROWS
  340. X%token K_BYCOLS
  341. X%token K_BYGRAPH
  342. X%token K_ITERATIONS
  343. X%token K_NUMERIC
  344. X%token K_PRESCALE
  345. X%token K_EXTFUN
  346. X%token K_CELLCUR
  347. X%token K_TOPROW
  348. X%token K_TBLSTYLE
  349. X%token K_TBL
  350. X%token K_LATEX
  351. X%token K_TEX
  352. X
  353. X%left '?' ':'
  354. X%left '|'
  355. X%left '&'
  356. X%nonassoc '<' '=' '>' '!'
  357. X%left '+' '-' '#'
  358. X%left '*' '/' '%'
  359. X%left '^'
  360. X
  361. X%%
  362. Xcommand:    S_LET var_or_range '=' e
  363. X                { let($2.left.vp, $4); }
  364. X    |    S_LABEL var_or_range '=' e
  365. X                { slet($2.left.vp, $4, 0); }
  366. X    |    S_LEFTSTRING var_or_range '=' e
  367. X                { slet($2.left.vp, $4, -1); }
  368. X    |    S_RIGHTSTRING var_or_range '=' e
  369. X                { slet($2.left.vp, $4, 1); }
  370. X    |    S_FORMAT COL ':' COL NUMBER NUMBER
  371. X                { doformat($2,$4,$5,$6); }
  372. X    |    S_FORMAT COL NUMBER NUMBER
  373. X                { doformat($2,$2,$3,$4); }
  374. X    |    S_GET strarg    {  /* This tmp hack is because readfile
  375. X                    * recurses back through yyparse. */
  376. X                  char *tmp;
  377. X                  tmp = $2;
  378. X                  readfile (tmp, 1);
  379. X                  xfree(tmp);
  380. X                }
  381. X    |    S_MERGE strarg    {
  382. X                  char *tmp;
  383. X                  tmp = $2;
  384. X                  readfile (tmp, 0);
  385. X                  xfree(tmp);
  386. X                }
  387. X    |    S_MDIR strarg    
  388. X                { if (mdir) xfree(mdir); mdir = $2; }
  389. X    |       S_PUT strarg range
  390. X                { (void) writefile($2, ($3.left.vp)->row, 
  391. X                 ($3.left.vp)->col, ($3.right.vp)->row,
  392. X                 ($3.right.vp)->col);
  393. X                 xfree($2); }
  394. X    |    S_PUT strarg    
  395. X                { (void) writefile ($2, 0, 0, maxrow, maxcol);
  396. X                 xfree($2); }
  397. X    |       S_WRITE strarg range { (void) printfile($2, ($3.left.vp)->row, 
  398. X             ($3.left.vp)->col, ($3.right.vp)->row,
  399. X             ($3.right.vp)->col);
  400. X             xfree($2); }
  401. X    |    S_WRITE strarg    { (void) printfile ($2, 0, 0, maxrow, maxcol);
  402. X             xfree($2); }
  403. X    |       S_TBL strarg range { (void) tblprintfile($2, ($3.left.vp)->row, 
  404. X             ($3.left.vp)->col, ($3.right.vp)->row,
  405. X             ($3.right.vp)->col);
  406. X             xfree($2); }
  407. X    |    S_TBL strarg    { (void)tblprintfile ($2, 0, 0, maxrow, maxcol);
  408. X             xfree($2); }
  409. X    |       S_SHOW COL ':' COL
  410. X                    { showcol( $2, $4); }
  411. X    |       S_SHOW NUMBER ':' NUMBER
  412. X                    { showrow( $2, $4); }
  413. X     |    S_HIDE COL
  414. X                     { hide_col( $2 ); }
  415. X     |    S_HIDE NUMBER
  416. X                     { hide_row( $2 ); }
  417. X    |    S_COPY range var_or_range 
  418. X                    { copy($2.left.vp,$2.right.vp,
  419. X                    $3.left.vp,$3.right.vp); }
  420. X    |    S_ERASE       
  421. X                    { eraser(lookat(showsr, showsc),
  422. X                        lookat(currow, curcol)); }
  423. X    |    S_ERASE var_or_range 
  424. X                    { eraser($2.left.vp, $2.right.vp); }
  425. X    |    S_VALUE       { valueize_area(showsr, showsc, currow, curcol);
  426. X                 modflg++; }
  427. X    |    S_VALUE var_or_range { valueize_area(($2.left.vp)->row,
  428. X                ($2.left.vp)->col,
  429. X                ($2.right.vp)->row,
  430. X                ($2.right.vp)->col); modflg++; }
  431. X    |    S_FILL num num  { fill(lookat(showsr, showsc),
  432. X                      lookat(currow, curcol), $2, $3); }
  433. X    |    S_FILL var_or_range num num
  434. X                 { fill($2.left.vp, $2.right.vp, $3, $4); }
  435. X    |    S_GOTO var_or_range {moveto($2.left.vp->row, $2.left.vp->col);}
  436. X    |       S_GOTO num          {num_search($2);}
  437. X    |       S_GOTO STRING       {str_search($2);}
  438. X    |    S_GOTO              {go_last();}
  439. X    |    S_DEFINE strarg       { struct ent_ptr arg1, arg2;
  440. X                    arg1.vp = lookat(showsr, showsc);
  441. X                    arg1.vf = 0;
  442. X                    arg2.vp = lookat(currow, curcol);
  443. X                    arg2.vf = 0;
  444. X                    add_range($2, arg1, arg2, 1); }
  445. X
  446. X    |    S_DEFINE strarg range { add_range($2, $3.left, $3.right, 1); }
  447. X    |    S_DEFINE strarg var   { add_range($2, $3, $3, 0); }
  448. X    |    S_UNDEFINE var_or_range { del_range($2.left.vp, $2.right.vp); }
  449. X     |    S_SET setlist
  450. X    |    /* nothing */
  451. X    |    error;
  452. X
  453. Xterm:         var        { $$ = new_var('v', $1); }
  454. X    |    K_FIXED term    { $$ = new ('f', ENULL, $2); }
  455. X    |       '@' K_SUM '(' var_or_range ')' 
  456. X                { $$ = new_range(REDUCE | '+', $4); }
  457. X    |       '@' K_PROD '(' var_or_range ')' 
  458. X                { $$ = new_range (REDUCE | '*', $4); }
  459. X    |       '@' K_AVG '(' var_or_range ')' 
  460. X                { $$ = new_range (REDUCE | 'a', $4); }
  461. X    |       '@' K_STDDEV '(' var_or_range ')' 
  462. X                { $$ = new_range (REDUCE | 's', $4); }
  463. X    |       '@' K_COUNT '(' var_or_range ')' 
  464. X                { $$ = new_range (REDUCE | 'c', $4); }
  465. X    |       '@' K_MAX '(' var_or_range ')' 
  466. X                { $$ = new_range (REDUCE | MAX, $4); }
  467. X    |    '@' K_MAX '(' e ',' expr_list ')'
  468. X                { $$ = new(LMAX, $6, $4); }
  469. X    |       '@' K_MIN '(' var_or_range ')' 
  470. X                { $$ = new_range (REDUCE | MIN, $4); }
  471. X    |    '@' K_MIN '(' e ',' expr_list ')'
  472. X                { $$ = new(LMIN, $6, $4); }
  473. X    | '@' K_ABS '(' e ')'     { $$ = new(ABS, ENULL, $4); }
  474. X    | '@' K_ACOS '(' e ')'     { $$ = new(ACOS, ENULL, $4); }
  475. X    | '@' K_ASIN '(' e ')'     { $$ = new(ASIN, ENULL, $4); }
  476. X    | '@' K_ATAN '(' e ')'     { $$ = new(ATAN, ENULL, $4); }
  477. X    | '@' K_ATAN2 '(' e ',' e ')' { $$ = new(ATAN2, $4, $6); }
  478. X    | '@' K_CEIL '(' e ')'     { $$ = new(CEIL, ENULL, $4); }
  479. X    | '@' K_COS '(' e ')'     { $$ = new(COS, ENULL, $4); }
  480. X    | '@' K_EXP '(' e ')'     { $$ = new(EXP, ENULL, $4); }
  481. X    | '@' K_FABS '(' e ')'     { $$ = new(FABS, ENULL, $4); }
  482. X    | '@' K_FLOOR '(' e ')'     { $$ = new(FLOOR, ENULL, $4); }
  483. X    | '@' K_HYPOT '(' e ',' e ')'    { $$ = new(HYPOT, $4, $6); }
  484. X    | '@' K_LN '(' e ')'     { $$ = new(LOG, ENULL, $4); }
  485. X    | '@' K_LOG '(' e ')'     { $$ = new(LOG10, ENULL, $4); }
  486. X    | '@' K_POW '(' e ',' e ')'    { $$ = new(POW, $4, $6); }
  487. X    | '@' K_SIN '(' e ')'     { $$ = new(SIN, ENULL, $4); }
  488. X    | '@' K_SQRT '(' e ')'     { $$ = new(SQRT, ENULL, $4); }
  489. X    | '@' K_TAN '(' e ')'     { $$ = new(TAN, ENULL, $4); }
  490. X    | '@' K_DTR '(' e ')'     { $$ = new(DTR, ENULL, $4); }
  491. X    | '@' K_RTD '(' e ')'     { $$ = new(RTD, ENULL, $4); }
  492. X    | '@' K_RND '(' e ')'     { $$ = new(RND, ENULL, $4); }
  493. X    | '@' K_ROUND '(' e ',' e ')'     { $$ = new(ROUND, $4, $6); }
  494. X    | '@' K_IF  '(' e ',' e ',' e ')' { $$ = new(IF,  $4,new(',',$6,$8)); }
  495. X
  496. X    | '@' K_PV  '(' e ',' e ',' e ')' { $$ = new(PV,  $4,new(':',$6,$8)); }
  497. X     | '@' K_FV  '(' e ',' e ',' e ')' { $$ = new(FV,  $4,new(':',$6,$8)); }
  498. X     | '@' K_PMT '(' e ',' e ',' e ')' { $$ = new(PMT, $4,new(':',$6,$8)); }
  499. X    | '@' K_HOUR '(' e ')'      { $$ = new(HOUR,ENULL, $4); }
  500. X    | '@' K_MINUTE '(' e ')' { $$ = new(MINUTE,ENULL, $4); }
  501. X    | '@' K_SECOND '(' e ')' { $$ = new(SECOND,ENULL, $4); }
  502. X    | '@' K_MONTH '(' e ')'     { $$ = new(MONTH,ENULL,$4); }
  503. X    | '@' K_DAY '(' e ')'    { $$ = new(DAY, ENULL, $4); }
  504. X    | '@' K_YEAR '(' e ')'   { $$ = new(YEAR, ENULL, $4); }
  505. X    | '@' K_NOW              { $$ = new(NOW, ENULL, ENULL);}
  506. X    | '@' K_DTS '(' e ',' e ',' e ')'
  507. X                   { $$ = new(DTS, $4, new(',', $6, $8));}
  508. X    | '@' K_TTS '(' e ',' e ',' e ')'
  509. X                   { $$ = new(TTS, $4, new(',', $6, $8));}
  510. X    | '@' K_STON '(' e ')'   { $$ = new(STON, ENULL, $4); }
  511. X    | '@' K_EQS '(' e ',' e ')' { $$ = new (EQS, $4, $6); }
  512. X    | '@' K_DATE '(' e ')'     { $$ = new(DATE, ENULL, $4); }
  513. X    | '@' K_FMT  '(' e ',' e ')' { $$ = new(FMT, $4, $6); }
  514. X    | '@' K_INDEX  '(' e ',' var_or_range ')'
  515. X         { $$ = new(INDEX, $4, new_range(REDUCE | INDEX, $6)); }
  516. X    | '@' K_LOOKUP  '(' e ',' var_or_range ')'
  517. X         { $$ = new(LOOKUP, $4, new_range(REDUCE | LOOKUP, $6)); }
  518. X    | '@' K_HLOOKUP  '(' e ',' var_or_range ',' e ')'
  519. X         { $$ = new(HLOOKUP, new(',', $4, $8),
  520. X            new_range(REDUCE | HLOOKUP, $6)); }
  521. X    | '@' K_VLOOKUP  '(' e ',' var_or_range ',' e ')'
  522. X         { $$ = new(VLOOKUP, new(',', $4, $8),
  523. X            new_range(REDUCE | VLOOKUP, $6)); }
  524. X    | '@' K_STINDEX  '(' e ',' var_or_range ')'
  525. X         { $$ = new(STINDEX, $4, new_range(REDUCE | STINDEX, $6)); }
  526. X    | '@' K_EXT  '(' e ',' e ')' { $$ = new(EXT, $4, $6); }
  527. X    | '@' K_NVAL '(' e ',' e ')' { $$ = new(NVAL, $4, $6); }
  528. X    | '@' K_SVAL '(' e ',' e ')' { $$ = new(SVAL, $4, $6); }
  529. X    | '@' K_SUBSTR '(' e ',' e ',' e ')'
  530. X                 { $$ = new(SUBSTR, $4, new(',', $6, $8)); }
  531. X    |    '(' e ')'     { $$ = $2; }
  532. X    |    '+' term     { $$ = $2; }
  533. X    |    '-' term     { $$ = new ('m', ENULL, $2); }
  534. X    |    NUMBER         { $$ = new_const('k', (double) $1); }
  535. X    |    FNUMBER         { $$ = new_const('k', $1); }
  536. X    |    K_PI    { $$ = new_const('k', (double)3.14159265358979323846); }
  537. X    |    STRING             { $$ = new_str($1); }
  538. X    |    '~' term     { $$ = new ('~', ENULL, $2); }
  539. X    |    '!' term     { $$ = new ('~', ENULL, $2); }
  540. X    ;
  541. X
  542. Xe:        e '+' e        { $$ = new ('+', $1, $3); }
  543. X    |    e '-' e        { $$ = new ('-', $1, $3); }
  544. X    |    e '*' e        { $$ = new ('*', $1, $3); }
  545. X    |    e '/' e        { $$ = new ('/', $1, $3); }
  546. X    |    e '%' e        { $$ = new ('%', $1, $3); }
  547. X    |    e '^' e        { $$ = new ('^', $1, $3); }
  548. X    |    term
  549. X    |    e '?' e ':' e    { $$ = new ('?', $1, new(':', $3, $5)); }
  550. X    |    e '<' e        { $$ = new ('<', $1, $3); }
  551. X    |    e '=' e        { $$ = new ('=', $1, $3); }
  552. X    |    e '>' e        { $$ = new ('>', $1, $3); }
  553. X    |    e '&' e        { $$ = new ('&', $1, $3); }
  554. X    |    e '|' e        { $$ = new ('|', $1, $3); }
  555. X    |    e '<' '=' e    { $$ = new ('~', ENULL, new ('>', $1, $4)); }
  556. X    |    e '!' '=' e    { $$ = new ('~', ENULL, new ('=', $1, $4)); }
  557. X    |    e '>' '=' e    { $$ = new ('~', ENULL, new ('<', $1, $4)); }
  558. X    |    e '#' e        { $$ = new ('#', $1, $3); }
  559. X    ;
  560. X
  561. Xexpr_list:    e        { $$ = new(ELIST, ENULL, $1); }
  562. X    |    expr_list ',' e    { $$ = new(ELIST, $1, $3); }
  563. X    ;
  564. X
  565. Xrange:        var ':' var    { $$.left = $1; $$.right = $3; }
  566. X    |     RANGE        { $$ = $1; }
  567. X    ;
  568. X
  569. Xvar:        COL NUMBER    { $$.vp = lookat($2 , $1); $$.vf = 0;}
  570. X    |    '$' COL NUMBER    { $$.vp = lookat($3 , $2);
  571. X                    $$.vf = FIX_COL;}
  572. X    |    COL '$' NUMBER    { $$.vp = lookat($3 , $1);
  573. X                    $$.vf = FIX_ROW;}
  574. X    |    '$' COL '$' NUMBER { $$.vp = lookat($4 , $2);
  575. X                    $$.vf = FIX_ROW | FIX_COL;}
  576. X    |    VAR        { $$ = $1.left; }
  577. X    ;
  578. X
  579. Xvar_or_range:    range        { $$ = $1; }
  580. X    |    var        { $$.left = $1; $$.right = $1; }
  581. X    ;
  582. X
  583. Xnum:        NUMBER        { $$ = (double) $1; }
  584. X    |    FNUMBER        { $$ = $1; }
  585. X    |    '-' num        { $$ = -$2; }
  586. X    |    '+' num        { $$ = $2; }
  587. X    ;
  588. X
  589. Xstrarg:        STRING        { $$ = $1; }
  590. X    |    var        {
  591. X                    char *s, *s1;
  592. X                    s1 = $1.vp->label;
  593. X                    if (!s1)
  594. X                    s1 = "NULL_STRING";
  595. X                    s = xmalloc((unsigned)strlen(s1)+1);
  596. X                    (void) strcpy(s, s1);
  597. X                    $$ = s;
  598. X                }
  599. X      ;
  600. X
  601. Xsetlist :    
  602. X    |    setlist setitem
  603. X    ;
  604. X
  605. Xsetitem    :    K_AUTO        { setauto(1); }
  606. X    |    K_AUTOCALC    { setauto(1); }
  607. X    |    '~' K_AUTO    { setauto(0); }
  608. X    |    '~' K_AUTOCALC    { setauto(0); }
  609. X    |    '!' K_AUTO    { setauto(0); }
  610. X    |    '!' K_AUTOCALC    { setauto(0); }
  611. X    |    K_BYCOLS    { setorder(BYCOLS); }
  612. X    |    K_BYROWS    { setorder(BYROWS); }
  613. X    |    K_BYGRAPH    { setorder(BYGRAPH); }
  614. X    |    K_NUMERIC    { numeric = 1; }
  615. X    |    '!' K_NUMERIC    { numeric = 0; }
  616. X    |    K_PRESCALE    { prescale = 0.01; }
  617. X    |    '!' K_PRESCALE    { prescale = 1.0; }
  618. X    |    K_EXTFUN    { extfunc = 1; }
  619. X    |    '!' K_EXTFUN    { extfunc = 0; }
  620. X    |    K_CELLCUR    { showcell = 1; }
  621. X    |    '!' K_CELLCUR    { showcell = 0; }
  622. X    |    K_TOPROW    { showtop = 1; }
  623. X    |    '!' K_TOPROW    { showtop = 0; }
  624. X    |    K_ITERATIONS '=' NUMBER    { setiterations($3); }
  625. X    |    K_TBLSTYLE '=' NUMBER    { tbl_style = $3; }
  626. X    |    K_TBLSTYLE '=' K_TBL    { tbl_style = TBL; }
  627. X    |    K_TBLSTYLE '=' K_LATEX    { tbl_style = LATEX; }
  628. X    |    K_TBLSTYLE '=' K_TEX    { tbl_style = TEX; }
  629. X      ;
  630. END_OF_FILE
  631.   if test 12082 -ne `wc -c <'gram.y'`; then
  632.     echo shar: \"'gram.y'\" unpacked with wrong size!
  633.   fi
  634.   # end of 'gram.y'
  635. fi
  636. if test -f 'psc.doc' -a "${1}" != "-c" ; then 
  637.   echo shar: Will not clobber existing file \"'psc.doc'\"
  638. else
  639.   echo shar: Extracting \"'psc.doc'\" \(2147 characters\)
  640.   sed "s/^X//" >'psc.doc' <<'END_OF_FILE'
  641. X.\" $Revision $
  642. X.TH PPNAME 1
  643. X.SH NAME
  644. Xppname \- prepare pname files
  645. X.SH SYNOPSIS
  646. X.B ppname
  647. X[
  648. X.I -fLkr
  649. X]
  650. X[
  651. X.I -s cell
  652. X]
  653. X[
  654. X.I -R n
  655. X]
  656. X[
  657. X.I -C n
  658. X]
  659. X[
  660. X.I -n n
  661. X]
  662. X[
  663. X.I -d c
  664. X]
  665. X
  666. X.SH DESCRIPTION
  667. X.I Ppname
  668. Xis used to prepare data for input to the spread sheet calculator
  669. X.I pname(1).
  670. XIt accepts normal ascii data on standard input.  Standard output
  671. Xis a
  672. X.I pname
  673. Xfile.
  674. XWith no options, 
  675. X.I ppname
  676. Xstarts the spread sheet in cell A0.  Strings are right justified.
  677. XAll data on a line is entered on the same row; new input lines
  678. Xcause the output row number to increment by one.  The default delimiters
  679. Xare tab and space.  The column formats are set to one larger
  680. Xthan the number of columns required to hold the largest value
  681. Xin the column.
  682. X
  683. XOptions:
  684. X
  685. X.IP "\-f"
  686. XOmit column width calculations.  This option is for preparing
  687. Xdata to be merged with an existing spreadsheet.  If the option is not
  688. Xspecified, the column widths calculated for the data read by
  689. X.I ppname
  690. Xwill override those already set in the existing spreadsheet.
  691. X
  692. X.IP "\-L"
  693. XLeft justify strings.
  694. X
  695. X.IP "\-k"
  696. XKeep all delimiters.  This option causes the output cell to change on
  697. Xeach new delimiter encountered in the input stream.   The default
  698. Xaction is to condense multiple delimters to one, so that the cell only
  699. Xchanges once per input data item.
  700. X
  701. X.IP "\-r"
  702. XOutput the data by row first then column.  For input consisting of a single
  703. Xcolumn, this
  704. Xoption will result in output of one row with multiple columns
  705. Xinstead of a single
  706. Xcolumn spread sheet.
  707. X
  708. X.IP "\-s cell"
  709. XStart the top left corner of the spread sheet in 
  710. X.I cell.
  711. XFor example, 
  712. X.I "-s B33"
  713. Xwill arrange the output data so that the
  714. Xspread sheet starts in column B, row 33.
  715. X
  716. X.IP "\-R n"
  717. XIncrement by
  718. X.I n 
  719. Xon each new output row.
  720. X
  721. X.IP "\-C n"
  722. XIncrement by
  723. X.I n 
  724. Xon each new output column.
  725. X
  726. X.IP "\-n n"
  727. XOutput 
  728. X.I n
  729. Xrows before advancing to the next column.  This option is used when
  730. Xthe input is arranged in a single column and the spread sheet is to
  731. Xhave multiple columns, each of which is to be length
  732. X.I n.
  733. X
  734. X.IP "\-d c"
  735. XUse the single character
  736. X.I c
  737. Xas the delimiter between input fields.
  738. X
  739. X.SH SEE ALSO
  740. Xpname(1)
  741. X
  742. X.SH AUTHOR
  743. X
  744. XRobert Bond
  745. END_OF_FILE
  746.   if test 2147 -ne `wc -c <'psc.doc'`; then
  747.     echo shar: \"'psc.doc'\" unpacked with wrong size!
  748.   fi
  749.   # end of 'psc.doc'
  750. fi
  751. if test -f 'range.c' -a "${1}" != "-c" ; then 
  752.   echo shar: Will not clobber existing file \"'range.c'\"
  753. else
  754.   echo shar: Extracting \"'range.c'\" \(5604 characters\)
  755.   sed "s/^X//" >'range.c' <<'END_OF_FILE'
  756. X
  757. X/*    SC    A Spreadsheet Calculator
  758. X *        Range Manipulations
  759. X *
  760. X *              Robert Bond, 4/87
  761. X *
  762. X *        $Revision: 6.8 $
  763. X */
  764. X
  765. X#include <stdio.h>
  766. X#include <curses.h>
  767. X#include <ctype.h>
  768. X#include "sc.h"
  769. X
  770. X#ifdef BSD42
  771. X#include <strings.h>
  772. X#else
  773. X#ifndef SYSIII
  774. X#include <string.h>
  775. X#endif
  776. X#endif
  777. X
  778. Xstatic struct range *rng_base;
  779. X
  780. Xadd_range(name, left, right, is_range)
  781. Xchar *name;
  782. Xstruct ent_ptr left, right;
  783. Xint is_range;
  784. X{
  785. X    struct range *r;
  786. X    register char *p;
  787. X    int len;
  788. X    int minr,minc,maxr,maxc;
  789. X    int minrf, mincf, maxrf, maxcf;
  790. X
  791. X    if (left.vp->row < right.vp->row) {
  792. X    minr = left.vp->row; minrf = left.vf & FIX_ROW;
  793. X    maxr = right.vp->row; maxrf = right.vf & FIX_ROW;
  794. X    } else {
  795. X    minr = right.vp->row; minrf = right.vf & FIX_ROW;
  796. X    maxr = left.vp->row; maxrf = right.vf & FIX_ROW;
  797. X    } 
  798. X
  799. X    if (left.vp->col < right.vp->col) {
  800. X    minc = left.vp->col; mincf = left.vf & FIX_COL;
  801. X    maxc = right.vp->col; maxcf = right.vf & FIX_COL;
  802. X    } else {
  803. X    minc = right.vp->col; mincf = right.vf & FIX_COL;
  804. X    maxc = left.vp->col; maxcf = left.vf & FIX_COL;
  805. X    } 
  806. X
  807. X    left.vp = lookat(minr, minc);
  808. X    left.vf = minrf | mincf;
  809. X    right.vp = lookat(maxr, maxc);
  810. X    right.vf = maxrf | maxcf;
  811. X
  812. X    if (find_range(name, strlen(name), (struct ent *)0, (struct ent *)0)) {
  813. X    error("Error: range name already defined");
  814. X    xfree(name);
  815. X    return;
  816. X    }
  817. X
  818. X    if (strlen(name) <= 2) {
  819. X    error("Invalid range name - too short");
  820. X    xfree(name);
  821. X    return;
  822. X    }
  823. X
  824. X    for(p=name, len=0; *p; p++, len++)
  825. X    if (!((isalpha(*p) && (len<=2)) ||
  826. X        ((isdigit(*p) || isalpha(*p) || (*p == '_')) && (len>2)))) {
  827. X        error("Invalid range name - illegal combination");
  828. X        xfree(name);
  829. X        return;
  830. X        }
  831. X
  832. X    r = (struct range *)xmalloc((unsigned)sizeof(struct range));
  833. X    r->r_name = name;
  834. X    r->r_left = left;
  835. X    r->r_right = right;
  836. X    r->r_next = rng_base;
  837. X    r->r_prev = (struct range *)0;
  838. X    r->r_is_range = is_range;
  839. X    if (rng_base)
  840. X        rng_base->r_prev = r;
  841. X    rng_base = r;
  842. X}
  843. X
  844. Xdel_range(left, right)
  845. Xstruct ent *left, *right;
  846. X{
  847. X    register struct range *r;
  848. X    int minr,minc,maxr,maxc;
  849. X
  850. X    minr = left->row < right->row ? left->row : right->row;
  851. X    minc = left->col < right->col ? left->col : right->col;
  852. X    maxr = left->row > right->row ? left->row : right->row;
  853. X    maxc = left->col > right->col ? left->col : right->col;
  854. X
  855. X    left = lookat(minr, minc);
  856. X    right = lookat(maxr, maxc);
  857. X
  858. X    if (!(r = find_range((char *)0, 0, left, right))) 
  859. X    return;
  860. X
  861. X    if (r->r_next)
  862. X        r->r_next->r_prev = r->r_prev;
  863. X    if (r->r_prev)
  864. X        r->r_prev->r_next = r->r_next;
  865. X    else
  866. X    rng_base = r->r_next;
  867. X    xfree((char *)(r->r_name));
  868. X    xfree((char *)r);
  869. X}
  870. X
  871. Xclean_range()
  872. X{
  873. X    register struct range *r;
  874. X    register struct range *nextr;
  875. X
  876. X    r = rng_base;
  877. X    rng_base = (struct range *)0;
  878. X
  879. X    while (r) {
  880. X    nextr = r->r_next;
  881. X    xfree((char *)(r->r_name));
  882. X    xfree((char *)r);
  883. X    r = nextr;
  884. X    }
  885. X}
  886. X
  887. X/* Match on name or lmatch, rmatch */
  888. X
  889. Xstruct range *
  890. Xfind_range(name, len, lmatch, rmatch)
  891. Xchar *name;
  892. Xint len;
  893. Xstruct ent *lmatch;
  894. Xstruct ent *rmatch;
  895. X{
  896. X    struct range *r;
  897. X    register char *rp, *np;
  898. X    register int c;
  899. X
  900. X    if (name) {
  901. X    for (r = rng_base; r; r = r->r_next) {
  902. X        for (np = name, rp = r->r_name, c = len;
  903. X         c && *rp && (*rp == *np);
  904. X         rp++, np++, c--) /* */;
  905. X        if (!c && !*rp)
  906. X        return(r);
  907. X    }
  908. X    return((struct range *)0);
  909. X    }
  910. X
  911. X    for (r = rng_base; r; r= r->r_next) {
  912. X    if ((lmatch == r->r_left.vp) && (rmatch == r->r_right.vp)) 
  913. X        return(r);
  914. X    }
  915. X    return((struct range *)0);
  916. X}
  917. X
  918. Xsync_ranges()
  919. X{
  920. X    register struct range *r;
  921. X
  922. X    r = rng_base;
  923. X    while(r) {
  924. X    r->r_left.vp = lookat(r->r_left.vp->row, r->r_left.vp->col);
  925. X    r->r_right.vp = lookat(r->r_right.vp->row, r->r_right.vp->col);
  926. X    r = r->r_next;
  927. X    }
  928. X}
  929. X
  930. Xwrite_range(f)
  931. XFILE *f;
  932. X{
  933. X    register struct range *r;
  934. X
  935. X    for (r = rng_base; r; r = r->r_next) {
  936. X    (void) fprintf(f, "define \"%s\" %s%s%s%d",
  937. X            r->r_name,
  938. X            r->r_left.vf & FIX_COL ? "$":"",
  939. X            coltoa(r->r_left.vp->col), 
  940. X            r->r_left.vf & FIX_ROW ? "$":"",
  941. X            r->r_left.vp->row);
  942. X    if (r->r_is_range)
  943. X        (void) fprintf(f, ":%s%s%s%d\n",
  944. X                r->r_right.vf & FIX_COL ? "$":"",
  945. X                coltoa(r->r_right.vp->col), 
  946. X                r->r_right.vf & FIX_ROW ? "$":"",
  947. X                r->r_right.vp->row);
  948. X    else
  949. X        (void) fprintf(f, "\n");
  950. X    }
  951. X}
  952. X
  953. Xvoid
  954. Xlist_range(f)
  955. XFILE *f;
  956. X{
  957. X    register struct range *r;
  958. X
  959. X    (void) fprintf(f, "%-30s %s\n\n","Name","Definition");
  960. X
  961. X    for (r = rng_base; r; r = r->r_next) {
  962. X    (void) fprintf(f, "%-30s %s%s%s%d",
  963. X                r->r_name,
  964. X                r->r_left.vf & FIX_COL ? "$":"",
  965. X                coltoa(r->r_left.vp->col), 
  966. X                r->r_left.vf & FIX_ROW ? "$":"",
  967. X                r->r_left.vp->row);
  968. X    if (r->r_is_range)
  969. X        (void) fprintf(f, ":%s%s%s%d\n",
  970. X                r->r_right.vf & FIX_COL ? "$":"",
  971. X                coltoa(r->r_right.vp->col), 
  972. X                r->r_right.vf & FIX_ROW ? "$":"",
  973. X                r->r_right.vp->row);
  974. X    else
  975. X        (void) fprintf(f, "\n");
  976. X    }
  977. X}
  978. X
  979. Xchar *
  980. Xv_name(row, col)
  981. Xint row, col;
  982. X{
  983. X    struct ent *v;
  984. X    struct range *r;
  985. X    static char buf[20];
  986. X
  987. X    v = lookat(row, col);
  988. X    if (r = find_range((char *)0, 0, v, v)) {
  989. X    return(r->r_name);
  990. X    } else {
  991. X        (void) sprintf(buf, "%s%d", coltoa(col), row);
  992. X    return(buf);
  993. X    }
  994. X}
  995. X
  996. Xchar *
  997. Xr_name(r1, c1, r2, c2)
  998. Xint r1, c1, r2, c2;
  999. X{
  1000. X    struct ent *v1, *v2;
  1001. X    struct range *r;
  1002. X    static char buf[100];
  1003. X
  1004. X    v1 = lookat(r1, c1);
  1005. X    v2 = lookat(r2, c2);
  1006. X    if (r = find_range((char *)0, 0, v1, v2)) {
  1007. X    return(r->r_name);
  1008. X    } else {
  1009. X        (void) sprintf(buf, "%s", v_name(r1, c1));
  1010. X    (void) sprintf(buf+strlen(buf), ":%s", v_name(r2, c2));
  1011. X    return(buf);
  1012. X    }
  1013. X}
  1014. X
  1015. Xare_ranges()
  1016. X{
  1017. Xreturn (rng_base != 0);
  1018. X}
  1019. END_OF_FILE
  1020.   if test 5604 -ne `wc -c <'range.c'`; then
  1021.     echo shar: \"'range.c'\" unpacked with wrong size!
  1022.   fi
  1023.   # end of 'range.c'
  1024. fi
  1025. if test -f 'sc.h' -a "${1}" != "-c" ; then 
  1026.   echo shar: Will not clobber existing file \"'sc.h'\"
  1027. else
  1028.   echo shar: Extracting \"'sc.h'\" \(8426 characters\)
  1029.   sed "s/^X//" >'sc.h' <<'END_OF_FILE'
  1030. X/*    SC    A Table Calculator
  1031. X *        Common definitions
  1032. X *
  1033. X *        original by James Gosling, September 1982
  1034. X *        modified by Mark Weiser and Bruce Israel,
  1035. X *            University of Maryland
  1036. X *        R. Bond  12/86
  1037. X *        More mods by Alan Silverstein, 3-4/88, see list of changes.
  1038. X *        $Revision: 6.8 $
  1039. X *
  1040. X */
  1041. X
  1042. X#define    ATBL(tbl, row, col)    (*(tbl + row) + (col))
  1043. X
  1044. X#define MINROWS 40    /* minimum size at startup */
  1045. X#define MINCOLS 20
  1046. X#define    ABSMAXCOLS 702    /* absolute cols: ZZ (base 26) */
  1047. X#define RESCOL 4    /* columns reserved for row numbers */
  1048. X#define RESROW 3 /* rows reserved for prompt, error, and column numbers */
  1049. X#define DEFWIDTH 10    /* Default column width and precision */
  1050. X#define DEFPREC   2
  1051. X#define HISTLEN  10    /* Number of history entries for vi emulation */
  1052. X#define error (void)move(1,0), (void)clrtoeol(), (void) printw
  1053. X#define    FBUFLEN    1024    /* buffer size for a single field */
  1054. X#define    PATHLEN    1024    /* maximum path length */
  1055. X
  1056. X#ifndef A_CHARTEXT    /* Should be defined in curses.h */
  1057. X#ifdef INTERNATIONAL
  1058. X#define A_CHARTEXT 0xff
  1059. X#else
  1060. X#define A_CHARTEXT 0x7f
  1061. X#endif
  1062. X#endif
  1063. X
  1064. X#if (defined(BSD42) || defined(BSD43)) && !defined(strrchr)
  1065. X#define strrchr rindex
  1066. X#endif
  1067. X
  1068. Xstruct ent_ptr {
  1069. X    int vf;
  1070. X    struct ent *vp;
  1071. X};
  1072. X
  1073. Xstruct range_s {
  1074. X    struct ent_ptr left, right;
  1075. X};
  1076. X
  1077. X/*
  1078. X * Some not too obvious things about the flags:
  1079. X *    is_valid means there is a valid number in v.
  1080. X *    label set means it points to a valid constant string.
  1081. X *    is_strexpr set means expr yields a string expression.
  1082. X *    If is_strexpr is not set, and expr points to an expression tree, the
  1083. X *        expression yields a numeric expression.
  1084. X *    So, either v or label can be set to a constant. 
  1085. X *        Either (but not both at the same time) can be set from an expression.
  1086. X */
  1087. X
  1088. X#define VALID_CELL(p, r, c) ((p = *ATBL(tbl, r, c)) && \
  1089. X                 ((p->flags & is_valid) || p->label))
  1090. X
  1091. Xstruct ent {
  1092. X    double v;
  1093. X    char *label;
  1094. X    struct enode *expr;
  1095. X    short flags;
  1096. X    short row, col;
  1097. X    struct ent *next;        /* next deleted ent */
  1098. X    struct ent *evnext;        /* next ent w/ a object to eval */
  1099. X    struct ent *evprev;        /* prev ent w/ a object to eval */
  1100. X};
  1101. X
  1102. Xstruct range {
  1103. X    struct ent_ptr r_left, r_right;
  1104. X    char *r_name;
  1105. X    struct range *r_next, *r_prev;
  1106. X    int r_is_range;
  1107. X};
  1108. X
  1109. X#define FIX_ROW 1
  1110. X#define FIX_COL 2
  1111. X
  1112. Xstruct enode {
  1113. X    int op;
  1114. X    union {
  1115. X    double k;
  1116. X    struct ent_ptr v;
  1117. X    struct range_s r;
  1118. X    char *s;
  1119. X    struct {
  1120. X        struct enode *left, *right;
  1121. X    } o;
  1122. X    } e;
  1123. X};
  1124. X
  1125. X/* op values */
  1126. X#define O_VAR 'v'
  1127. X#define O_CONST 'k'
  1128. X#define O_SCONST '$'
  1129. X#define REDUCE 0200    /* Or'ed into OP if operand is a range */
  1130. X
  1131. X#define OP_BASE 256
  1132. X#define ACOS OP_BASE + 0
  1133. X#define ASIN OP_BASE + 1
  1134. X#define ATAN OP_BASE + 2
  1135. X#define CEIL OP_BASE + 3
  1136. X#define COS OP_BASE + 4
  1137. X#define EXP OP_BASE + 5 
  1138. X#define FABS OP_BASE + 6 
  1139. X#define FLOOR OP_BASE + 7
  1140. X#define HYPOT OP_BASE + 8
  1141. X#define LOG OP_BASE + 9
  1142. X#define LOG10 OP_BASE + 10
  1143. X#define POW OP_BASE + 11
  1144. X#define SIN OP_BASE + 12
  1145. X#define SQRT OP_BASE + 13
  1146. X#define TAN OP_BASE + 14
  1147. X#define DTR OP_BASE + 15
  1148. X#define RTD OP_BASE + 16
  1149. X#define MIN OP_BASE + 17
  1150. X#define MAX OP_BASE + 18
  1151. X#define RND OP_BASE + 19
  1152. X#define HOUR OP_BASE + 20
  1153. X#define MINUTE OP_BASE + 21
  1154. X#define SECOND OP_BASE + 22
  1155. X#define MONTH OP_BASE + 23
  1156. X#define DAY OP_BASE + 24
  1157. X#define YEAR OP_BASE + 25
  1158. X#define NOW OP_BASE + 26
  1159. X#define DATE OP_BASE + 27
  1160. X#define FMT OP_BASE + 28
  1161. X#define SUBSTR OP_BASE + 29
  1162. X#define STON OP_BASE + 30
  1163. X#define EQS OP_BASE + 31
  1164. X#define EXT OP_BASE + 32
  1165. X#define ELIST OP_BASE + 33    /* List of expressions */
  1166. X#define LMAX  OP_BASE + 34
  1167. X#define LMIN  OP_BASE + 35
  1168. X#define NVAL OP_BASE + 36
  1169. X#define SVAL OP_BASE + 37
  1170. X#define PV OP_BASE + 38
  1171. X#define FV OP_BASE + 39
  1172. X#define PMT OP_BASE + 40
  1173. X#define STINDEX OP_BASE + 41
  1174. X#define LOOKUP OP_BASE + 42
  1175. X#define ATAN2 OP_BASE + 43
  1176. X#define INDEX OP_BASE + 44
  1177. X#define DTS OP_BASE + 45
  1178. X#define TTS OP_BASE + 46
  1179. X#define ABS OP_BASE + 47 
  1180. X#define HLOOKUP OP_BASE + 48
  1181. X#define VLOOKUP OP_BASE + 49
  1182. X#define ROUND OP_BASE + 50
  1183. X#define IF OP_BASE + 51
  1184. X
  1185. X/* flag values */
  1186. X#define is_valid     0001
  1187. X#define is_changed   0002
  1188. X#define is_strexpr   0004
  1189. X#define is_leftflush 0010
  1190. X#define is_deleted   0020
  1191. X
  1192. X#define ctl(c) ((c)&037)
  1193. X#define ESC 033
  1194. X#define DEL 0177
  1195. X
  1196. X#define BYCOLS 1
  1197. X#define BYROWS 2
  1198. X#define BYGRAPH 4        /* Future */
  1199. X
  1200. X#define    TBL    1        /* tblprint style output for 'tbl' */
  1201. X#define    LATEX    2        /* tblprint style output for 'LaTeX' */
  1202. X#define    TEX    3        /* tblprint style output for 'TeX' */
  1203. X
  1204. X/* Types for etype() */
  1205. X
  1206. X#define NUM    1
  1207. X#define STR    2
  1208. X
  1209. X#define    GROWAMT    10    /* default minimum amount to grow */
  1210. X
  1211. X#define    GROWNEW        1    /* first time table */
  1212. X#define    GROWROW        2    /* add rows */
  1213. X#define    GROWCOL        3
  1214. X#define    GROWBOTH    4
  1215. Xextern    struct ent ***tbl;
  1216. X
  1217. Xextern    char curfile[];
  1218. Xextern    int strow, stcol;
  1219. Xextern    int currow, curcol;
  1220. Xextern    int savedrow, savedcol;
  1221. Xextern    int FullUpdate;
  1222. Xextern    int maxrow, maxcol;
  1223. Xextern    int maxrows, maxcols;    /* # cells currently allocated */
  1224. Xextern    int *fwidth;
  1225. Xextern    int *precision;
  1226. Xextern    char *col_hidden;
  1227. Xextern    char *row_hidden;
  1228. Xextern    char line[FBUFLEN];
  1229. Xextern    int linelim;
  1230. Xextern    int changed;
  1231. Xextern    struct ent *to_fix;
  1232. Xextern    int showsc, showsr;
  1233. X
  1234. Xextern    FILE *openout();
  1235. Xextern    char *coltoa();
  1236. Xextern    char *findhome();
  1237. Xextern    char *r_name();
  1238. Xextern    char *seval();
  1239. Xextern    char *strrchr();
  1240. Xextern    char *v_name();
  1241. Xextern    char *xmalloc();
  1242. Xextern    double dolookup();
  1243. Xextern    double eval();
  1244. Xextern    int RealEvalAll();
  1245. Xextern    int are_ranges();
  1246. Xextern    int atocol();
  1247. Xextern    int constant();
  1248. Xextern    int etype();
  1249. Xextern    int fork();
  1250. Xextern    int get_rcqual();
  1251. Xextern    int growtbl();
  1252. Xextern    int nmgetch();
  1253. Xextern    int writefile();
  1254. Xextern    int xfree();
  1255. Xextern    int yn_ask();
  1256. Xextern    struct enode *copye();
  1257. Xextern    struct enode *new();
  1258. Xextern    struct enode *new_const();
  1259. Xextern    struct enode *new_range();
  1260. Xextern    struct enode *new_str();
  1261. Xextern    struct enode *new_var();
  1262. Xextern    struct ent *lookat();
  1263. Xextern    struct range *find_range();
  1264. Xextern    void EvalAll();
  1265. Xextern    void Evalall();
  1266. Xextern    void RealEvalOne();
  1267. Xextern    void backcol();
  1268. Xextern    void backrow();
  1269. Xextern    void checkbounds();
  1270. Xextern    void clearent();
  1271. Xextern    void closecol();
  1272. Xextern    void closeout();
  1273. Xextern    void closerow();
  1274. Xextern    void colshow_op();
  1275. Xextern    void colvalueize();
  1276. Xextern    void colvalueize();
  1277. Xextern    void copy();
  1278. Xextern    void copyent();
  1279. Xextern    void copyrtv();
  1280. Xextern    void decompile();
  1281. Xextern    void deletecol();
  1282. Xextern    void deleterow();
  1283. Xextern    void deraw();
  1284. Xextern    void doend();
  1285. Xextern    void doformat();
  1286. Xextern    void dupcol();
  1287. Xextern    void duprow();
  1288. Xextern    void editexp();
  1289. Xextern    void edits();
  1290. Xextern    void editv();
  1291. Xextern    void efree();
  1292. Xextern    void erase_area();
  1293. Xextern    void erasedb();
  1294. Xextern    void eraser();
  1295. Xextern    void fill();
  1296. Xextern    void flush_saved();
  1297. Xextern    void forwcol();
  1298. Xextern    void forwrow();
  1299. Xextern    void free_ent();
  1300. Xextern    void go_last();
  1301. Xextern    void goraw();
  1302. Xextern    void help();
  1303. Xextern    void hide_col();
  1304. Xextern    void hide_row();
  1305. Xextern    void hidecol();
  1306. Xextern    void hiderow();
  1307. Xextern    void index_arg();
  1308. Xextern    void ins_string();
  1309. Xextern    void insert_mode();
  1310. Xextern    void insertcol();
  1311. Xextern    void insertrow();
  1312. Xextern    void kbd_again();
  1313. Xextern    void label();
  1314. Xextern    void let();
  1315. Xextern    void list_arg();
  1316. Xextern    void list_range();
  1317. Xextern    void moveto();
  1318. Xextern    void num_search();
  1319. Xextern    void one_arg();
  1320. Xextern    void opencol();
  1321. Xextern    void openrow();
  1322. Xextern    void printfile();
  1323. Xextern    void pullcells();
  1324. Xextern    void range_arg();
  1325. Xextern    void readfile();
  1326. Xextern    void repaint();
  1327. Xextern    void resetkbd();
  1328. Xextern    void rowshow_op();
  1329. Xextern    void rowvalueize();
  1330. Xextern    void setauto();
  1331. Xextern    void setiterations();
  1332. Xextern    void setorder();
  1333. Xextern    void showcol();
  1334. Xextern    void showdr();
  1335. Xextern    void showrow();
  1336. Xextern    void showstring();
  1337. Xextern    void signals();
  1338. Xextern    void slet();
  1339. Xextern    void startshow();
  1340. Xextern    void str_search();
  1341. Xextern    void sync_refs();
  1342. Xextern    void syncref();
  1343. Xextern    void tblprintfile();
  1344. Xextern    void three_arg();
  1345. Xextern    void two_arg();
  1346. Xextern    void two_arg_index();
  1347. Xextern    void update();
  1348. Xextern    void valueize_area();
  1349. Xextern    void write_fd();
  1350. Xextern    void write_line();
  1351. Xextern    void yyerror();
  1352. X#ifdef DOBACKUPS
  1353. Xextern    int backup_file();
  1354. X#endif
  1355. X
  1356. Xextern    int modflg;
  1357. Xextern    int Crypt;
  1358. Xextern    char *mdir;
  1359. Xextern    double prescale;
  1360. Xextern    int extfunc;
  1361. Xextern    int propagation;
  1362. Xextern    int calc_order;
  1363. Xextern    int autocalc;
  1364. Xextern    int numeric;
  1365. Xextern    int showcell;
  1366. Xextern    int showtop;
  1367. Xextern    int loading;
  1368. Xextern    int getrcqual;
  1369. Xextern    int tbl_style;
  1370. Xextern    char *progname;
  1371. X
  1372. X#if BSD42 || SYSIII
  1373. X
  1374. X#ifndef cbreak
  1375. X#define    cbreak        crmode
  1376. X#define    nocbreak    nocrmode
  1377. X#endif
  1378. X
  1379. X#endif
  1380. END_OF_FILE
  1381.   if test 8426 -ne `wc -c <'sc.h'`; then
  1382.     echo shar: \"'sc.h'\" unpacked with wrong size!
  1383.   fi
  1384.   # end of 'sc.h'
  1385. fi
  1386. if test -f 'version.c' -a "${1}" != "-c" ; then 
  1387.   echo shar: Will not clobber existing file \"'version.c'\"
  1388. else
  1389.   echo shar: Extracting \"'version.c'\" \(148 characters\)
  1390.   sed "s/^X//" >'version.c' <<'END_OF_FILE'
  1391. X/*
  1392. X * CODE REVISION NUMBER:
  1393. X *
  1394. X * The part after the first colon, except the last char, appears on the screen.
  1395. X */
  1396. X
  1397. Xchar *rev = "$Revision: 6.8 $";
  1398. END_OF_FILE
  1399.   if test 148 -ne `wc -c <'version.c'`; then
  1400.     echo shar: \"'version.c'\" unpacked with wrong size!
  1401.   fi
  1402.   # end of 'version.c'
  1403. fi
  1404. if test -f 'vi.c' -a "${1}" != "-c" ; then 
  1405.   echo shar: Will not clobber existing file \"'vi.c'\"
  1406. else
  1407.   echo shar: Extracting \"'vi.c'\" \(10584 characters\)
  1408.   sed "s/^X//" >'vi.c' <<'END_OF_FILE'
  1409. X/*    SC    A Spreadsheet Calculator
  1410. X *
  1411. X *    One line vi emulation
  1412. X *    $Revision: 6.8 $
  1413. X */
  1414. X
  1415. X
  1416. X#include <signal.h>
  1417. X#include <curses.h>
  1418. X
  1419. X#ifdef BSD42
  1420. X#include <strings.h>
  1421. X#else
  1422. X#ifndef SYSIII
  1423. X#include <string.h>
  1424. X#endif
  1425. X#endif
  1426. X
  1427. X#if !defined(strchr) && !defined(UPORT)
  1428. X#define strchr index
  1429. X#endif
  1430. Xextern    char    *strchr();
  1431. X
  1432. X#include <stdio.h>
  1433. X#include <ctype.h>
  1434. X#include "sc.h"
  1435. X
  1436. X#define istext(a) (isalnum(a) || ((a) == '_'))
  1437. X
  1438. Xextern int showrange;
  1439. Xextern char mode_ind;        /* Mode indicator */
  1440. X
  1441. X/* values for mode below */
  1442. X
  1443. X#define INSERT_MODE    0    /* Insert mode */
  1444. X#define EDIT_MODE       1    /* Edit mode */
  1445. X#define REP_MODE        2    /* Replace mode */
  1446. X#define SEARCH_MODE    3    /* Get arguments for '/' command */
  1447. Xstatic int mode = INSERT_MODE;
  1448. Xstatic char *history[HISTLEN];
  1449. Xstatic int histp = -1;
  1450. Xstatic char *last_search;
  1451. Xstatic char *undo_line;
  1452. Xstatic int undo_lim;
  1453. Xstatic char dotb[100];
  1454. Xstatic int doti = 0;
  1455. Xstatic int do_dot = 0;
  1456. X
  1457. Xvoid
  1458. Xwrite_line(c)
  1459. Xint c;
  1460. X{
  1461. X    if (mode == EDIT_MODE) {
  1462. X    switch(c) {
  1463. X    case (ctl('h')):    linelim = back_line();        break;
  1464. X    case (ctl('m')):  cr_line();            break;
  1465. X    case ESC:    stop_edit();            break;
  1466. X    case '+':    for_hist();            break;
  1467. X    case '-':    back_hist();            break;
  1468. X    case '$':    last_col();            break;
  1469. X    case '.':    dotcmd();            break;
  1470. X    case '/':    search_mode();            break;
  1471. X    case '0':    col_0();            break;
  1472. X    case 'D':    u_save(c);del_to_end();        break;
  1473. X    case 'I':    u_save(c);col_0();insert_mode();break;
  1474. X    case 'R':    replace_mode();            break;
  1475. X    case 'X':    u_save(c); back_space();    break;
  1476. X    case 'a':    u_save(c); append_line();    break;
  1477. X    case 'b':    linelim = back_word();        break;
  1478. X    case 'c':    u_save(c); change_cmd();    break;
  1479. X    case 'd':    u_save(c); delete_cmd();    break;
  1480. X    case 'f':    linelim = find_char();        break;
  1481. X    case 'h':    linelim = back_line();        break;
  1482. X    case 'i':    u_save(c); insert_mode();    break;
  1483. X    case 'j':    for_hist();            break;
  1484. X    case 'k':    back_hist();            break;
  1485. X    case 'l':    linelim = for_line(0);        break;
  1486. X    case 'n':    search_again();            break;
  1487. X    case 'q':    stop_edit();            break;
  1488. X    case 'r':    u_save(c); rep_char();        break;
  1489. X    case 't':    linelim = to_char();        break;
  1490. X    case 'u':    restore_it();            break;
  1491. X    case 'w':    linelim = for_word(0);        break;
  1492. X    case 'x':    u_save(c); del_in_line();    break;
  1493. X    default:    break;
  1494. X    }
  1495. X    } else if (mode == INSERT_MODE) { 
  1496. X    savedot(c);
  1497. X    switch(c) {
  1498. X    case (ctl('h')):    back_space();            break;
  1499. X    case (ctl('m')):  cr_line();            break;
  1500. X    case ESC:    edit_mode();            break;
  1501. X    default:    ins_in_line(c);            break;
  1502. X    }
  1503. X    } else if (mode == SEARCH_MODE) {
  1504. X    switch(c) {
  1505. X    case (ctl('h')):    back_space();            break;
  1506. X    case (ctl('m')):  search_hist();            break;
  1507. X    case ESC:    edit_mode();            break;
  1508. X    default:    ins_in_line(c);            break;
  1509. X    }
  1510. X   } else if (mode == REP_MODE) {
  1511. X    savedot(c);
  1512. X    switch(c) {
  1513. X    case (ctl('h')):    back_space();            break;
  1514. X    case (ctl('m')):  cr_line();            break;
  1515. X    case ESC:    edit_mode();            break;
  1516. X    default:    replace_in_line(c);        break;
  1517. X    }
  1518. X    }
  1519. X}
  1520. X
  1521. Xedit_mode()
  1522. X{
  1523. X    mode = EDIT_MODE;
  1524. X    mode_ind = 'e';
  1525. X    histp = -1;
  1526. X    if (line[linelim] == '\0')
  1527. X    linelim = back_line();
  1528. X}
  1529. X
  1530. Xvoid
  1531. Xinsert_mode()
  1532. X{
  1533. X    mode_ind = 'i';
  1534. X    mode = INSERT_MODE;
  1535. X}
  1536. X
  1537. Xsearch_mode()
  1538. X{
  1539. X    line[0] = '/';
  1540. X    line[1] = 0;
  1541. X    linelim = 1;
  1542. X    histp = -1;
  1543. X    mode_ind = '/';
  1544. X    mode = SEARCH_MODE;
  1545. X}
  1546. X
  1547. Xreplace_mode()
  1548. X{
  1549. X    mode_ind = 'R';
  1550. X    mode = REP_MODE;
  1551. X}
  1552. X
  1553. X/* dot command functions.  Saves info so we can redo on a '.' command */
  1554. X
  1555. Xsavedot(c)
  1556. Xint c;
  1557. X{
  1558. X    if (do_dot)
  1559. X    return;
  1560. X
  1561. X    dotb[doti++] = c;
  1562. X    dotb[doti] = 0;
  1563. X}
  1564. X
  1565. Xdotcmd()
  1566. X{
  1567. X    int c;
  1568. X
  1569. X    do_dot = 1;
  1570. X    doti = 0;
  1571. X    while(dotb[doti] != 0) {
  1572. X    c = dotb[doti++];
  1573. X    write_line(c);
  1574. X    }
  1575. X    do_dot = 0;
  1576. X    doti = 0;
  1577. X}
  1578. X
  1579. Xvigetch()
  1580. X{
  1581. X    int c;
  1582. X
  1583. X    if(do_dot) {
  1584. X    if (dotb[doti] != 0) {
  1585. X        return(dotb[doti++]);
  1586. X    } else {
  1587. X        do_dot = 0;
  1588. X        doti = 0;
  1589. X        return(nmgetch());
  1590. X    }
  1591. X    }
  1592. X    c = nmgetch();
  1593. X    savedot(c);
  1594. X    return(c);
  1595. X}
  1596. X
  1597. X/* saves the current line for possible use by an undo cmd */
  1598. X
  1599. Xu_save(c)
  1600. Xint c;
  1601. X{
  1602. X    if (undo_line) {
  1603. X    xfree(undo_line);
  1604. X    undo_line = 0;
  1605. X    }
  1606. X    undo_line = strcpy(xmalloc((unsigned)(strlen(line)+1)), line);
  1607. X    undo_lim = linelim;
  1608. X
  1609. X    /* reset dot command if not processing it. */
  1610. X
  1611. X    if (!do_dot) {
  1612. X        doti = 0;
  1613. X    savedot(c);
  1614. X    }
  1615. X}
  1616. X
  1617. X/* Restores the current line saved by u_save() */
  1618. X
  1619. Xrestore_it()
  1620. X{
  1621. X    register char *tempc;
  1622. X    register int tempi;
  1623. X
  1624. X    if (!undo_line)
  1625. X    return;
  1626. X    tempc = strcpy(xmalloc((unsigned)(strlen(line)+1)), line);
  1627. X    tempi = linelim;
  1628. X    strcpy(line, undo_line);
  1629. X    linelim = undo_lim;
  1630. X    xfree(undo_line);
  1631. X    undo_line = tempc;
  1632. X    undo_lim = tempi;
  1633. X}
  1634. X
  1635. X/* This command stops the editing process. */
  1636. X
  1637. Xstop_edit()
  1638. X{
  1639. X    showrange = 0;
  1640. X    linelim = -1;
  1641. X    (void) move(1, 0);
  1642. X    (void) clrtoeol();
  1643. X}
  1644. X
  1645. X/*
  1646. X * Motion commands.  Forward motion commands take an argument
  1647. X * which, when set, cause the forward motion to continue onto
  1648. X * the null at the end of the line instead of stopping at the
  1649. X * the last character of the line.
  1650. X */
  1651. X
  1652. Xfor_line(stop_null)
  1653. Xint stop_null;
  1654. X{
  1655. X    if (linelim >= 0 && line[linelim] != 0 && 
  1656. X                    (line[linelim+1] != 0 || stop_null))
  1657. X    return(linelim+1);
  1658. X    else
  1659. X    return(linelim);
  1660. X}
  1661. X
  1662. Xfor_word(stop_null)
  1663. Xint stop_null;
  1664. X{
  1665. X    register int c;
  1666. X    register int cpos;
  1667. X
  1668. X    cpos = linelim;
  1669. X
  1670. X    if (line[cpos] == ' ') {
  1671. X    while (line[cpos] == ' ')
  1672. X        cpos++;
  1673. X    if (cpos > 0 && line[cpos] == 0)
  1674. X        --cpos;
  1675. X    return(cpos);
  1676. X    }
  1677. X
  1678. X    if (istext(line[cpos])) {
  1679. X        while ((c = line[cpos]) && istext(c)) 
  1680. X        cpos++;
  1681. X    } else {
  1682. X    while ((c = line[cpos]) && !istext(c) && c != ' ')
  1683. X        cpos++;
  1684. X    }
  1685. X
  1686. X    while (line[cpos] == ' ')
  1687. X        cpos++;
  1688. X
  1689. X    if (cpos > 0 && line[cpos] == 0 && !stop_null) 
  1690. X        --cpos;
  1691. X
  1692. X    return(cpos);
  1693. X}
  1694. X
  1695. Xback_line()
  1696. X{
  1697. X    if (linelim)
  1698. X        return(linelim-1);
  1699. X    else
  1700. X    return(0);
  1701. X}
  1702. X
  1703. Xback_word()
  1704. X{
  1705. X    register int c;
  1706. X    register int cpos;
  1707. X
  1708. X    cpos = linelim;
  1709. X
  1710. X    if (line[cpos] == ' ') {
  1711. X    /* Skip white space */
  1712. X        while (cpos > 0 && line[cpos] == ' ')
  1713. X        --cpos;
  1714. X    } else if (cpos > 0 && (line[cpos-1] == ' ' 
  1715. X             ||  istext(line[cpos]) && !istext(line[cpos-1])
  1716. X             || !istext(line[cpos]) &&  istext(line[cpos-1]))) {
  1717. X    /* Started on the first char of a word - back up to prev. word */
  1718. X    --cpos;
  1719. X        while (cpos > 0 && line[cpos] == ' ')
  1720. X        --cpos;
  1721. X    }
  1722. X
  1723. X    /* Skip across the word - goes 1 too far */
  1724. X    if (istext(line[cpos])) {
  1725. X        while (cpos > 0 && (c = line[cpos]) && istext(c)) 
  1726. X        --cpos;
  1727. X    } else {
  1728. X    while (cpos > 0 && (c = line[cpos]) && !istext(c) && c != ' ')
  1729. X        --cpos;
  1730. X    }
  1731. X
  1732. X    /* We are done - fix up the one too far */
  1733. X    if (cpos > 0 && line[cpos] && line[cpos+1]) 
  1734. X    cpos++;
  1735. X
  1736. X    return(cpos);
  1737. X}
  1738. X
  1739. X/* Text manipulation commands */
  1740. X
  1741. Xdel_in_line()
  1742. X{
  1743. X    register int len, i;
  1744. X
  1745. X    if (linelim >= 0) {
  1746. X    len = strlen(line);
  1747. X    if (linelim == len && linelim > 0)
  1748. X        linelim--;
  1749. X    for (i = linelim; i < len; i++)
  1750. X        line[i] = line[i+1];
  1751. X    }
  1752. X    if (linelim > 0 && line[linelim] == 0)
  1753. X    --linelim;
  1754. X}
  1755. X
  1756. Xins_in_line(c)
  1757. Xint c;
  1758. X{
  1759. X    register int i, len;
  1760. X
  1761. X    len = strlen(line);
  1762. X    for (i = len; i >= linelim; --i)
  1763. X    line[i+1] = line[i];
  1764. X    line[linelim++] = c;
  1765. X    line[len+1] = 0;
  1766. X}
  1767. X
  1768. Xvoid
  1769. Xins_string(s)
  1770. Xchar *s;
  1771. X{
  1772. X    while (*s)
  1773. X    ins_in_line(*s++);
  1774. X}
  1775. X
  1776. Xappend_line()
  1777. X{
  1778. X    register int i;
  1779. X
  1780. X    i = linelim;
  1781. X    if (i >= 0 && line[i])
  1782. X    linelim++;
  1783. X    insert_mode();
  1784. X}
  1785. X
  1786. Xrep_char()
  1787. X{
  1788. X    int c;
  1789. X
  1790. X    c = vigetch();
  1791. X    if (line[linelim] != 0) {
  1792. X        line[linelim] = c;
  1793. X    } else {
  1794. X    line[linelim] = c;
  1795. X    line[linelim+1] = 0;
  1796. X    }
  1797. X}
  1798. X
  1799. Xreplace_in_line(c)
  1800. X{
  1801. X    register int len;
  1802. X
  1803. X    len = strlen(line);
  1804. X    line[linelim++] = c;
  1805. X    if (linelim > len)
  1806. X    line[linelim] = 0;
  1807. X}
  1808. X    
  1809. Xback_space()
  1810. X{
  1811. X    if (linelim == 0)
  1812. X    return;
  1813. X
  1814. X    if (line[linelim] == 0) {
  1815. X    linelim = back_line();
  1816. X    del_in_line();
  1817. X    linelim = strlen(line);
  1818. X    } else {
  1819. X    linelim = back_line();
  1820. X    del_in_line();
  1821. X    }
  1822. X}
  1823. X
  1824. Xget_motion()
  1825. X{
  1826. X    int c;
  1827. X
  1828. X    c = vigetch();
  1829. X    switch (c) {
  1830. X    case 'b':    return(back_word());
  1831. X    case 'f':    return(find_char()+1);
  1832. X    case 'h':    return(back_line());
  1833. X    case 'l':    return(for_line(1));
  1834. X    case 't':    return(to_char()+1);
  1835. X    case 'w':    return(for_word(1));
  1836. X    default:    return(linelim);
  1837. X    }
  1838. X}
  1839. X
  1840. Xdelete_cmd()
  1841. X{
  1842. X    int cpos;
  1843. X
  1844. X    cpos = get_motion();
  1845. X    del_chars(cpos, linelim);
  1846. X}
  1847. X
  1848. Xchange_cmd()
  1849. X{
  1850. X    delete_cmd();
  1851. X    insert_mode();
  1852. X}
  1853. X
  1854. Xdel_chars(first, last)
  1855. Xregister int first, last;
  1856. X{
  1857. X    int temp;
  1858. X
  1859. X    if (first == last)
  1860. X    return;
  1861. X
  1862. X    if (last < first) {
  1863. X    temp = last; last = first; first = temp;
  1864. X    }
  1865. X
  1866. X    linelim = first;
  1867. X    while(first < last) {
  1868. X    del_in_line();
  1869. X    --last;
  1870. X    }
  1871. X}
  1872. X
  1873. Xdel_to_end()
  1874. X{
  1875. X    if (linelim < 0)
  1876. X    return;
  1877. X    line[linelim] = 0;
  1878. X    linelim = back_line();
  1879. X}
  1880. X
  1881. Xcr_line()
  1882. X{
  1883. X    showrange = 0;
  1884. X    insert_mode();
  1885. X    save_hist();
  1886. X    linelim = 0;
  1887. X    (void) yyparse ();
  1888. X    linelim = -1;
  1889. X}
  1890. X
  1891. X/* History functions */
  1892. X
  1893. Xsave_hist()
  1894. X{
  1895. X    register int i;
  1896. X
  1897. X    /* free the oldest one */
  1898. X    if (history[HISTLEN-1]) {
  1899. X    xfree(history[HISTLEN-1]);
  1900. X    history[HISTLEN-1] = 0;
  1901. X    }
  1902. X
  1903. X    /* Move the others back */
  1904. X    for (i = HISTLEN-1; i > 0; --i)
  1905. X    history[i] = history[i-1];
  1906. X
  1907. X    history[0] = xmalloc((unsigned) strlen(line)+1);
  1908. X    strcpy(history[0], line);
  1909. X}
  1910. X
  1911. Xback_hist()
  1912. X{
  1913. X    if (histp == -1 || histp < HISTLEN-1 && history[histp + 1])
  1914. X    histp++;
  1915. X
  1916. X    if (history[histp]) {
  1917. X        strcpy(line, history[histp]);
  1918. X    linelim = 0;
  1919. X    } else
  1920. X    line[linelim = 0] = 0;
  1921. X
  1922. X}
  1923. X
  1924. Xsearch_hist()
  1925. X{
  1926. X    if (last_search) {
  1927. X    xfree(last_search);
  1928. X    last_search = 0;
  1929. X    }
  1930. X
  1931. X    if(linelim < 1) {
  1932. X    linelim = 0;
  1933. X    edit_mode();
  1934. X    return;
  1935. X    }
  1936. X
  1937. X    last_search = strcpy(xmalloc((unsigned)(strlen(line+1)+1)), line+1);
  1938. X    search_again();
  1939. X    mode = EDIT_MODE;
  1940. X}
  1941. X
  1942. Xsearch_again()
  1943. X{
  1944. X    int found_it;
  1945. X    int do_next;
  1946. X    int prev_histp;
  1947. X    char *look_here;
  1948. X
  1949. X    prev_histp = histp;
  1950. X    if (!last_search)
  1951. X    return;
  1952. X
  1953. X    do {
  1954. X    back_hist();
  1955. X    if (prev_histp == histp)
  1956. X        break;
  1957. X    prev_histp = histp;
  1958. X    look_here = line;
  1959. X    found_it = do_next = 0;
  1960. X    while ((look_here = strchr(look_here, last_search[0])) &&
  1961. X                        !found_it && !do_next) {
  1962. X
  1963. X        if (strncmp(look_here, last_search, strlen(last_search)) == 0)
  1964. X        found_it++;
  1965. X        else if (look_here < line + strlen(line) - 1)
  1966. X            look_here++;
  1967. X        else
  1968. X        do_next++;
  1969. X    }
  1970. X    } while (!found_it);
  1971. X}
  1972. X
  1973. Xfor_hist()
  1974. X{
  1975. X    if (histp > 0)
  1976. X        histp--;
  1977. X
  1978. X    if (histp >= 0 && history[histp]) {
  1979. X        strcpy(line, history[histp]);
  1980. X    linelim = 0;
  1981. X    } else
  1982. X    line[linelim = 0] = 0;
  1983. X}
  1984. X
  1985. Xcol_0()
  1986. X{
  1987. X    linelim = 0;
  1988. X}
  1989. X
  1990. Xlast_col()
  1991. X{
  1992. X    linelim = strlen(line);
  1993. X    if (linelim > 0)
  1994. X    --linelim;
  1995. X}
  1996. X
  1997. Xfind_char()
  1998. X{
  1999. X    register int c;
  2000. X    register int i;
  2001. X
  2002. X
  2003. X    c = vigetch();
  2004. X    i = linelim;
  2005. X    while(line[i] && line[i] != c)
  2006. X    i++;
  2007. X    if (!line[i])
  2008. X    i = linelim;
  2009. X    return(i);
  2010. X}
  2011. X
  2012. Xto_char()
  2013. X{
  2014. X    register int i;
  2015. X
  2016. X    i = find_char();
  2017. X    if (i > 0 && i != linelim)
  2018. X    --i;
  2019. X
  2020. X    return(i);
  2021. X}
  2022. END_OF_FILE
  2023.   if test 10584 -ne `wc -c <'vi.c'`; then
  2024.     echo shar: \"'vi.c'\" unpacked with wrong size!
  2025.   fi
  2026.   # end of 'vi.c'
  2027. fi
  2028. if test -f 'vmtbl.c' -a "${1}" != "-c" ; then 
  2029.   echo shar: Will not clobber existing file \"'vmtbl.c'\"
  2030. else
  2031.   echo shar: Extracting \"'vmtbl.c'\" \(4643 characters\)
  2032.   sed "s/^X//" >'vmtbl.c' <<'END_OF_FILE'
  2033. X#ifdef PSC
  2034. X# include <stdio.h>
  2035. X# include "sc.h"
  2036. X# ifndef FALSE
  2037. X#  define    FALSE    0
  2038. X#  define    TRUE    1
  2039. X# endif /* !FALSE */
  2040. X# undef    error
  2041. X# define error(msg)    fprintf(stderr, msg);
  2042. X#else /* PSC */
  2043. X# include <curses.h>
  2044. X# include "sc.h"
  2045. X#endif /* PSC */
  2046. X
  2047. Xextern    char    *malloc();
  2048. Xextern    char    *realloc();
  2049. X
  2050. X#if defined(BSD42) || defined(BSD43)
  2051. X#define    memcpy(dest, source, len)    bcopy(source, dest, (unsigned int)len);
  2052. X#define    memset(dest, zero, len)        bzero((dest), (unsigned int)(len));
  2053. X#endif
  2054. X
  2055. X/*
  2056. X * check to see if *rowp && *colp are currently allocated, if not expand the
  2057. X * current size if we can.
  2058. X */
  2059. X#ifndef PSC
  2060. Xvoid
  2061. Xcheckbounds(rowp, colp)
  2062. Xint    *rowp;
  2063. Xint    *colp;
  2064. X{
  2065. X    if (*rowp < 0)
  2066. X        *rowp = 0;
  2067. X    else if (*rowp >= maxrows)
  2068. X    {    if (*colp >= maxcols)
  2069. X        {    if (!growtbl(GROWBOTH, *rowp, *colp))
  2070. X            {    *rowp = maxrows -1;
  2071. X                *colp = maxcols -1;
  2072. X            }
  2073. X            return;
  2074. X        }
  2075. X        else
  2076. X        {    if (!growtbl(GROWROW, *rowp, 0))
  2077. X                *rowp = maxrows-1;
  2078. X            return;
  2079. X        }
  2080. X    }
  2081. X    if (*colp < 0) 
  2082. X        *colp = 0;
  2083. X    else if (*colp >= maxcols)
  2084. X    {    if (!growtbl(GROWCOL, 0, *colp));
  2085. X            *colp = maxcols-1;
  2086. X    }
  2087. X}
  2088. X#endif /* !PSC */
  2089. X    
  2090. X
  2091. X#define GROWALLOC(newptr, oldptr, nelem, type, msg) \
  2092. X    if (oldptr == (type *)NULL) \
  2093. X        newptr = (type *)malloc((unsigned)(nelem*sizeof(type))); \
  2094. X    else \
  2095. X        newptr = (type *)realloc((char *)oldptr, \
  2096. X                     (unsigned)(nelem*sizeof(type))); \
  2097. X    if (newptr == (type *)NULL) \
  2098. X    {   error(msg); \
  2099. X        return(FALSE); \
  2100. X    } \
  2101. X    oldptr = newptr /* wait incase we can't alloc */
  2102. X
  2103. Xstatic    char    nolonger[] = "The table can't be any longer";
  2104. Xstatic    char    nowider[] = "The table can't be any wider";
  2105. X
  2106. X/*
  2107. X * grow the main && auxiliary tables (reset maxrows/maxcols as needed)
  2108. X * toprow &&/|| topcol tell us a better guess of how big to become.
  2109. X * we return TRUE if we could grow, FALSE if not....
  2110. X */
  2111. Xint
  2112. Xgrowtbl(rowcol, toprow, topcol)
  2113. Xint    rowcol;
  2114. Xint    toprow, topcol;
  2115. X{
  2116. X    struct ent ***tbl2;
  2117. X    int    *fwidth2;
  2118. X    int    *precision2;
  2119. X    char    *col_hidden2;
  2120. X    char    *row_hidden2;
  2121. X    int    newrows, newcols;
  2122. X    int    i;
  2123. X
  2124. X#ifndef PSC
  2125. X    newrows = maxrows;
  2126. X#endif /* !PSC */
  2127. X
  2128. X    newcols = maxcols;
  2129. X    if (rowcol == GROWNEW)
  2130. X    {
  2131. X#ifndef PSC
  2132. X        maxrows = toprow = 0;
  2133. X        /* when we first start up, fill the screen w/ cells */
  2134. X        {    int startval;
  2135. X            startval = LINES - RESROW;
  2136. X            newrows = startval > MINROWS ? startval : MINROWS;
  2137. X            startval = ((COLS) - RESCOL) / DEFWIDTH;
  2138. X            newcols = startval > MINCOLS ? startval : MINCOLS;
  2139. X        }
  2140. X#else
  2141. X        newcols = MINCOLS;
  2142. X#endif /* !PSC */
  2143. X        maxcols = topcol = 0;
  2144. X    }
  2145. X#ifndef PSC
  2146. X    /* set how much to grow */
  2147. X    if ((rowcol == GROWROW) || (rowcol == GROWBOTH))
  2148. X    {    if (toprow > maxrows)
  2149. X            newrows = GROWAMT + toprow;
  2150. X        else
  2151. X            newrows += GROWAMT;
  2152. X    }
  2153. X#endif /* !PSC */
  2154. X    if ((rowcol == GROWCOL) || (rowcol == GROWBOTH))
  2155. X    {    if ((rowcol == GROWCOL) && ((maxcols == ABSMAXCOLS) ||
  2156. X                    (topcol >= ABSMAXCOLS)))
  2157. X        {    error(nowider);
  2158. X            return(FALSE);
  2159. X        }
  2160. X
  2161. X        if (topcol > maxcols)
  2162. X            newcols = GROWAMT + topcol;
  2163. X        else
  2164. X            newcols += GROWAMT;
  2165. X
  2166. X        if (newcols > ABSMAXCOLS)
  2167. X            newcols = ABSMAXCOLS;
  2168. X    }
  2169. X
  2170. X#ifndef PSC
  2171. X    if ((rowcol == GROWROW) || (rowcol == GROWBOTH) || (rowcol == GROWNEW))
  2172. X    {
  2173. X        GROWALLOC(row_hidden2, row_hidden, newrows, char, nolonger);
  2174. X        memset(row_hidden+maxrows, 0, (newrows-maxrows)*sizeof(char));
  2175. X
  2176. X        /* alloc tbl row pointers */
  2177. X        GROWALLOC(tbl2, tbl, newrows, struct ent **, nolonger);
  2178. X        memset(tbl+maxrows, 0, (newrows-maxrows)*(sizeof(struct ent **)));
  2179. X    }
  2180. X#endif /* !PSC */
  2181. X
  2182. X    if ((rowcol == GROWCOL) || (rowcol == GROWBOTH) || (rowcol == GROWNEW))
  2183. X    {
  2184. X        GROWALLOC(fwidth2, fwidth, newcols, int, nowider);
  2185. X        GROWALLOC(precision2, precision, newcols, int, nowider);
  2186. X#ifdef PSC
  2187. X        memset(fwidth+maxcols, 0, (newcols-maxcols)*sizeof(int));
  2188. X        memset(precision+maxcols, 0, (newcols-maxcols)*sizeof(int));
  2189. X    }
  2190. X#else
  2191. X        GROWALLOC(col_hidden2, col_hidden, newcols, char, nowider);
  2192. X        memset(col_hidden+maxcols, 0, (newcols-maxcols)*sizeof(char));
  2193. X        for (i = maxcols; i < newcols; i++) {
  2194. X            fwidth[i] = DEFWIDTH;
  2195. X            precision[i] = DEFPREC;
  2196. X        }
  2197. X
  2198. X        /* [re]alloc the space for each row */
  2199. X        for (i = 0; i < maxrows; i++)
  2200. X        {
  2201. X            if ((tbl[i] = (struct ent **)realloc((char *)tbl[i],
  2202. X            (unsigned)(newcols * sizeof(struct ent **)))) == (struct ent **)0)
  2203. X            {    error(nowider);
  2204. X                return(FALSE);
  2205. X            }
  2206. X            memset((char *)ATBL(tbl,i, maxcols), 0,
  2207. X               (newcols-maxcols)*sizeof(struct ent **));
  2208. X        }
  2209. X    }
  2210. X    else
  2211. X        i = maxrows;
  2212. X
  2213. X    /* fill in the bottom of the table */
  2214. X    for (; i < newrows; i++)
  2215. X    {    if ((tbl[i] = (struct ent **)malloc((unsigned)(newcols *
  2216. X                sizeof(struct ent **)))) == (struct ent **)0)
  2217. X        {    error(nowider);
  2218. X            return(FALSE);
  2219. X        }
  2220. X        memset((char *)tbl[i], 0, newcols*sizeof(struct ent **));
  2221. X    }
  2222. X
  2223. X    FullUpdate++;
  2224. X    maxrows = newrows;
  2225. X#endif /* PSC */
  2226. X
  2227. X    maxcols = newcols;
  2228. X    return(TRUE);
  2229. X}
  2230. END_OF_FILE
  2231.   if test 4643 -ne `wc -c <'vmtbl.c'`; then
  2232.     echo shar: \"'vmtbl.c'\" unpacked with wrong size!
  2233.   fi
  2234.   # end of 'vmtbl.c'
  2235. fi
  2236. echo shar: End of archive 5 \(of 6\).
  2237. cp /dev/null ark5isdone
  2238. MISSING=""
  2239. for I in 1 2 3 4 5 6 ; do
  2240.     if test ! -f ark${I}isdone ; then
  2241.     MISSING="${MISSING} ${I}"
  2242.     fi
  2243. done
  2244. if test "${MISSING}" = "" ; then
  2245.     echo You have unpacked all 6 archives.
  2246.     rm -f ark[1-9]isdone
  2247. else
  2248.     echo You still must unpack the following archives:
  2249.     echo "        " ${MISSING}
  2250. fi
  2251. exit 0
  2252. exit 0 # Just in case...
  2253.